package com.zhiyou100.api.exception_demo;

import java.util.InputMismatchException;
import java.util.Scanner;

public class Demo3 {

    public static void main(String[] args) {
        int age;
        Scanner input = new Scanner(System.in);
        System.out.println("请输入您的年龄：");
        try {
            age = input.nextInt();    // 获取年龄
            if(age < 0) {
                //手动抛出去一个自定义异常
                throw new MyException("您输入的年龄为负数！输入有误！");
            } else if(age > 100) {
                throw new MyException("您输入的年龄大于100！输入有误！");
            } else {
                System.out.println("您的年龄为："+age);
            }
        } catch(InputMismatchException e1) {
            throw new MyException("您输入的不是数字，要求是整数!!!!");
        }finally {
            input.close();
        }
    }

}
